<!-- 侧边栏 -->
<nav class="sidebar" id="sidebar">
    <div class="p-3">
    <div class="user-profile">
        {% if user %}
            <div class="user-avatar">
                {% if user.avatar and user.avatar.strip() and not user.avatar.endswith('/') %}
                    <img src="{{ user.avatar }}" alt="用户头像">
                {% else %}
                    <img src="{{ url_for('static', filename='images/default-avatar.png') }}" alt="用户头像">
                {% endif %}
            </div>
            <div class="user-info">
                <h4>{{ user.real_name or user.username or '用户' }}</h4>
                {% if user.membership %}
                    {% set membership_names = {
                        'basic': '基础会员',
                        'professional': '专业会员', 
                        'institution': '机构会员',
                        'research': '科研会员'
                    } %}
                    <span class="member-badge member-{{ user.membership.plan_type }}">
                        {{ membership_names.get(user.membership.plan_type, '基础会员') }}
                    </span>
                {% else %}
                    <span class="member-badge member-basic">基础会员</span>
                {% endif %}
            </div>
        {% else %}
            <div class="user-avatar">
                <img src="{{ url_for('static', filename='images/default-avatar.png') }}" alt="用户头像">
            </div>
            <div class="user-info">
                <h4>用户</h4>
                <span class="member-badge member-basic">会员信息</span>
            </div>
        {% endif %}
    </div>
        <hr>
    </div>
    <ul class="nav flex-column">
        <li class="nav-item">
            <a class="nav-link {{ 'active' if request.endpoint == 'members.dashboard' }}" href="{{ url_for('members.dashboard') }}">
                <i class="bi bi-speedometer2 me-2"></i>工作台概览
            </a>
        </li>
        <li class="nav-item">
            <a class="nav-link {{ 'active' if request.endpoint == 'members.profile' }}" href="{{ url_for('members.profile') }}">
                <i class="bi bi-person-gear me-2"></i>个人信息
            </a>
        </li>
        <li class="nav-item">
            <a class="nav-link {{ 'active' if request.endpoint == 'members.my_scales' }}" href="{{ url_for('members.my_scales') }}">
                <i class="bi bi-journal-text me-2"></i>我的量表
            </a>
        </li>
     
        <li class="nav-item">
            <a class="nav-link {{ 'active' if request.endpoint == 'members.scale_publications' }}" href="{{ url_for('members.scale_publications') }}">
                <i class="bi bi-share me-2"></i>发布管理
            </a>
        </li>
      
        <li class="nav-item">
            <a class="nav-link {{ 'active' if request.endpoint == 'members.scale_library' }}" href="{{ url_for('members.scale_library') }}">
                <i class="bi bi-collection me-2"></i>系统内置量表库
            </a>
        </li>
        <li class="nav-item">
            <a class="nav-link {{ 'active' if request.endpoint == 'members.records' }}" href="{{ url_for('members.records') }}">
                <i class="bi bi-graph-up me-2"></i>测评记录
            </a>
        </li>
        <li class="nav-item">
            <a class="nav-link {{ 'active' if request.endpoint == 'members.analytics' }}" href="{{ url_for('members.analytics') }}">
                <i class="bi bi-bar-chart me-2"></i>数据分析
            </a>
        </li>
        <li class="nav-item mt-3">
            <hr>
        </li>
        <li class="nav-item">
            <a class="nav-link {{ 'active' if request.endpoint == 'members.plans' }}" href="{{ url_for('members.plans') }}">
                <i class="bi bi-star me-2"></i>会员套餐
            </a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="{{ url_for('main.index') }}">
                <i class="bi bi-house me-2"></i>返回首页
            </a>
        </li>
    </ul>
</nav>